﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FriendStar.Application.MainData;
using FriendStar.Application.WareHouse;
using FriendStar.Code;
using FriendStar.Domain.Entity.WareHouse;
using FriendStar.Repository.Infrastructure;

namespace FriendStar.Web.Areas.WareHouse.Controllers
{
    public class OutEntrustController : ControllerBase
    {
        //
        // GET: /WareHouse/OutEntrust/
        private string[] OutEntrustEnterType = { "WI", "WR" };
        private string[] OutEntrustOutType = { "WO", "WC" };
        private string[] OutEntrustBackType = { "WX" };
        private string[] OutEntrustWasteType = { "WS" };
        private string[] OutEntrustShelvesType = { "WP" };

        private string UseUnit = Configs.GetValue("UseUnit");
        private string FactoryFlag = Configs.GetValue("FactoryFlag");
        OutEntrustApp app = new OutEntrustApp();
        BUS_SJ_DictionaryApp bus_sj_dictionaryApp = new BUS_SJ_DictionaryApp();
        ZSJ_B1_GH_SupplierInformationApp zsj_b1_gh_supplierinformationApp = new ZSJ_B1_GH_SupplierInformationApp();
        CPK_ZD_11_DatStoreHouseApp cpk_zd_11_datstorehouseApp = new CPK_ZD_11_DatStoreHouseApp();
        WWK_ZD_12_DatStoreHouseSetApp wwk_zd_12_datstorehousesetApp = new WWK_ZD_12_DatStoreHouseSetApp();
        V_WWK_42_MX_StoCPKListAccoApp v_wwk_42_mx_stocpklistaccoApp = new V_WWK_42_MX_StoCPKListAccoApp();
        V_WWK_44_MX_StoCPKListAcco_MidApp v_wwk_44_mx_stocpklistacco_midApp = new V_WWK_44_MX_StoCPKListAcco_MidApp();
        V_WWK_47_MX_StoCPKListAcco_ArcApp v_wwk_47_mx_stocpklistacco_arcApp = new V_WWK_47_MX_StoCPKListAcco_ArcApp();
        V_ZSJ_12_GH_SuProduction_DatStorWWApp v_zsj_12_gh_suproduction_datstorwwApp = new V_ZSJ_12_GH_SuProduction_DatStorWWApp();
        V_CPK_61_PC_StoCPKAIAOAcco_AYWWApp v_cpk_61_pc_stocpkaiaoacco_aywwApp = new V_CPK_61_PC_StoCPKAIAOAcco_AYWWApp();
        WWK_42_MX_StoCPKListAccoApp wwk_42_mx_stocpklistaccoApp = new WWK_42_MX_StoCPKListAccoApp();

        #region 入库
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustEnter(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("IsProduct = '1'");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P7");
            ViewBag.accountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustEnterListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            var data = new
            {
                rows = v_wwk_42_mx_stocpklistaccoApp.GetList(pagination, OutEntrustEnterType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustEnterDocListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            if (AccountDate == FAccountDate)
            {
                var data = new
                {
                    rows = v_wwk_44_mx_stocpklistacco_midApp.GetList(pagination, OutEntrustEnterType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
            else
            {
                var data = new
                {
                    rows = v_wwk_47_mx_stocpklistacco_arcApp.GetList(pagination, OutEntrustEnterType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustEnterInput(string status, string number)
        {
            ViewBag.status = status != "B" ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList(OutEntrustEnterType);
            ViewBag.fdocunoTemp = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "外委入库", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustEnterListByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = new
                {
                    rows = v_wwk_42_mx_stocpklistaccoApp.GetListByDocuNO(FDocuNO)
                };
                result = data.ToJson();
            }
            else
            {
                
                string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = new
                    {
                        rows = v_wwk_44_mx_stocpklistacco_midApp.GetListByDocuNO(FDocuNO)
                    };
                    result = data.ToJson();
                }
                else
                {
                    var data = new
                    {
                        rows = v_wwk_47_mx_stocpklistacco_arcApp.GetListByDocuNO(FDocuNO)
                    };
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustEnterItemByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = v_wwk_42_mx_stocpklistaccoApp.GetItemByDocuNO(FDocuNO);
                result = data.ToJson();
            }
            else
            {
                
                string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = v_wwk_44_mx_stocpklistacco_midApp.GetItemByDocuNO(FDocuNO);
                    result = data.ToJson();
                }
                else
                {
                    var data = v_wwk_47_mx_stocpklistacco_arcApp.GetItemByDocuNO(FDocuNO);
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustEnterOrder(string number)
        {
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P7");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList(OutEntrustEnterType);
            ViewBag.fprocompanyList = zsj_b1_gh_supplierinformationApp.GetList("IsProduct = '1'");
            //ViewBag.fdocunoTemp = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "外委入库", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitOutEntrustEnterForm(string status, WWK_41_ML_StoCPKConAccoEntity entity, string detail, string keyValue)
        {
            string FFacNum = "";
            string DocNum = "";
            if (entity.FDocuTypeNO == "WI")
            {
                FFacNum = "外委入库";
            }
            else if (entity.FDocuTypeNO == "WR")
            {
                FFacNum = "自制入库";
            }
            WWK_42_MX_StoCPKListAccoEntity detailEntity = null;
            if (entity != null)
            {
                entity.FAccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
                detailEntity = detail.ToObject<WWK_42_MX_StoCPKListAccoEntity>();
            }
            if (status == "I")
            {
                if (!string.IsNullOrEmpty(entity.FDocuNO))
                {
                    var list = wwk_42_mx_stocpklistaccoApp.GetList(entity.FDocuNO, detailEntity.FProCompanyNO, detailEntity.FProductionNO);
                    if (list.Count > 0)
                    {
                        return Error("当前单据中已存在相同的零件和制造单位，入库信息输入操作失败。");
                    }
                }
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataInsert(UseUnit, entity, detailEntity, OperatorProvider.Provider.GetCurrent().UserCode, FactoryFlag, FFacNum, "正式", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("入库信息输入操作成功。", entity);
                }
                else
                {
                    return Error("入库信息输入操作失败。");
                }
            }
            else if (status == "D")
            {
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataDelete(keyValue, OperatorProvider.Provider.GetCurrent().UserCode);
                if (result)
                {
                    return Success("入库信息删除操作成功。", entity);
                }
                else
                {
                    return Error("入库信息删除操作失败。");
                }
            }
            else if (status == "U")
            {
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataUpdate(detailEntity.FDocuListID, detailEntity.FQuantity, detailEntity.FPrice_KP, OperatorProvider.Provider.GetCurrent().UserCode);
                if (result)
                {
                    return Success("入库信息修改操作成功。", entity);
                }
                else
                {
                    return Error("入库信息修改操作失败。");
                }
            }
            else if (status == "P")
            {
                bool result = false;
                foreach (string item in keyValue.Split(','))
                {
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataCheck(UseUnit, item, OperatorProvider.Provider.GetCurrent().UserCode);
                }
                if (result)
                {
                    return Success("入库信息审核操作成功。", entity);
                }
                else
                {
                    return Error("入库信息审核操作失败。");
                }
            }
            else if (status == "C")
            {
                V_WWK_44_MX_StoCPKListAcco_MidEntity midEntity = v_wwk_44_mx_stocpklistacco_midApp.GetForm(keyValue);
                if (midEntity.FQuantity.HasValue && midEntity.FQuantity.Value > 0)
                {
                    bool result = false;
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataRevoke(keyValue, OperatorProvider.Provider.GetCurrent().UserCode, FactoryFlag, FFacNum, "正式", out DocNum);
                    if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                    {
                        entity.FDocuNO = DocNum;
                    }
                    if (result)
                    {
                        return Success("入库信息冲红操作成功。", entity);
                    }
                    else
                    {
                        return Error("当前库存不足，入库信息冲红操作失败。");
                    }
                }
                else
                {
                    return Error("当前单据为冲红单，不可再进行冲红操作。");
                }
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        #endregion

        #region 出库
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustOut(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("IsProduct = '1'");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P7");
            ViewBag.accountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustOutListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            var data = new
            {
                rows = v_wwk_42_mx_stocpklistaccoApp.GetList(pagination, OutEntrustOutType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustOutDocListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            if (AccountDate == FAccountDate)
            {
                var data = new
                {
                    rows = v_wwk_44_mx_stocpklistacco_midApp.GetList(pagination, OutEntrustOutType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
            else
            {
                var data = new
                {
                    rows = v_wwk_47_mx_stocpklistacco_arcApp.GetList(pagination, OutEntrustOutType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustOutInput(string status, string number)
        {
            ViewBag.status = status != "B" ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList(OutEntrustOutType);
            ViewBag.fdocunoTemp = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "外委出库", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustOutListByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = new
                {
                    rows = v_wwk_42_mx_stocpklistaccoApp.GetListByDocuNO(FDocuNO)
                };
                result = data.ToJson();
            }
            else
            {
                
                string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = new
                    {
                        rows = v_wwk_44_mx_stocpklistacco_midApp.GetListByDocuNO(FDocuNO)
                    };
                    result = data.ToJson();
                }
                else
                {
                    var data = new
                    {
                        rows = v_wwk_47_mx_stocpklistacco_arcApp.GetListByDocuNO(FDocuNO)
                    };
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustOutItemByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = v_wwk_42_mx_stocpklistaccoApp.GetItemByDocuNO(FDocuNO);
                result = data.ToJson();
            }
            else
            {
                
                string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = v_wwk_44_mx_stocpklistacco_midApp.GetItemByDocuNO(FDocuNO);
                    result = data.ToJson();
                }
                else
                {
                    var data = v_wwk_47_mx_stocpklistacco_arcApp.GetItemByDocuNO(FDocuNO);
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustOutOrder(string number)
        {
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P7");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList(OutEntrustOutType);
            ViewBag.fprocompanyList = zsj_b1_gh_supplierinformationApp.GetList("IsProduct = '1'");
            //ViewBag.fdocunoTemp = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "外委出库", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitOutEntrustOutForm(string status, WWK_41_ML_StoCPKConAccoEntity entity, string detail, string keyValue)
        {
            string FFacNum = "";
            string DocNum = "";
            if (entity.FDocuTypeNO == "WO")
            {
                FFacNum = "外委出库";
            }
            else if (entity.FDocuTypeNO == "WC")
            {
                FFacNum = "自制出库";
            }
            WWK_42_MX_StoCPKListAccoEntity detailEntity = null;
            if (entity != null)
            {
                entity.FAccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
                detailEntity = detail.ToObject<WWK_42_MX_StoCPKListAccoEntity>();
            }
            if (status == "I")
            {
                //if (!string.IsNullOrEmpty(entity.FDocuNO))
                //{
                //    var list = wwk_42_mx_stocpklistaccoApp.GetList(entity.FDocuNO, detailEntity.FProCompanyNO, detailEntity.FProductionNO);
                //    if (list.Count > 0)
                //    {
                //        return Error("当前单据中已存在相同的零件和制造单位，出库信息输入操作失败。");
                //    }
                //}
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataInsert(UseUnit, entity, detailEntity, OperatorProvider.Provider.GetCurrent().UserCode, FactoryFlag, FFacNum, "正式", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("出库信息输入操作成功。", entity);
                }
                else
                {
                    return Error("库存不足，出库信息输入操作失败。");
                }
            }
            else if (status == "D")
            {
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataDelete(keyValue, OperatorProvider.Provider.GetCurrent().UserCode);
                if (result)
                {
                    return Success("出库信息删除操作成功。", entity);
                }
                else
                {
                    return Error("出库信息删除操作失败。");
                }
            }
            else if (status == "U")
            {
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataUpdate(detailEntity.FDocuListID, detailEntity.FQuantity, detailEntity.FPrice_KP, OperatorProvider.Provider.GetCurrent().UserCode);
                if (result)
                {
                    return Success("出库信息修改操作成功。", entity);
                }
                else
                {
                    return Error("出库信息修改操作失败。");
                }
            }
            else if (status == "P")
            {
                bool result = false;
                foreach (string item in keyValue.Split(','))
                {
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataCheck(UseUnit, item, OperatorProvider.Provider.GetCurrent().UserCode);
                }
                if (result)
                {
                    return Success("出库信息审核操作成功。", entity);
                }
                else
                {
                    return Error("出库信息审核操作失败。");
                }
            }
            else if (status == "C")
            {
                V_WWK_44_MX_StoCPKListAcco_MidEntity midEntity = v_wwk_44_mx_stocpklistacco_midApp.GetForm(keyValue);
                if (midEntity.FQuantity.HasValue && midEntity.FQuantity.Value > 0)
                {
                    bool result = false;
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataRevoke(keyValue, OperatorProvider.Provider.GetCurrent().UserCode, FactoryFlag, FFacNum, "正式", out DocNum);
                    if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                    {
                        entity.FDocuNO = DocNum;
                    }
                    if (result)
                    {
                        return Success("出库信息冲红操作成功。", entity);
                    }
                    else
                    {
                        return Error("当前库存不足，出库信息冲红操作失败。");
                    }
                }
                else
                {
                    return Error("当前单据为冲红单，不可再进行冲红操作。");
                }
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        #endregion

        #region 返修品登记
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustBack(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("IsProduct = '1'");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P7");
            ViewBag.accountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustBackListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            var data = new
            {
                rows = v_wwk_42_mx_stocpklistaccoApp.GetList(pagination, OutEntrustBackType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustBackDocListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            if (AccountDate == FAccountDate)
            {
                var data = new
                {
                    rows = v_wwk_44_mx_stocpklistacco_midApp.GetList(pagination, OutEntrustBackType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
            else
            {
                var data = new
                {
                    rows = v_wwk_47_mx_stocpklistacco_arcApp.GetList(pagination, OutEntrustBackType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustBackInput(string status, string number)
        {
            ViewBag.status = status != "B" ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList(OutEntrustBackType);
            ViewBag.fdocunoTemp = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "外委库返修", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustBackListByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = new
                {
                    rows = v_wwk_42_mx_stocpklistaccoApp.GetListByDocuNO(FDocuNO)
                };
                result = data.ToJson();
            }
            else
            {

                string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = new
                    {
                        rows = v_wwk_44_mx_stocpklistacco_midApp.GetListByDocuNO(FDocuNO)
                    };
                    result = data.ToJson();
                }
                else
                {
                    var data = new
                    {
                        rows = v_wwk_47_mx_stocpklistacco_arcApp.GetListByDocuNO(FDocuNO)
                    };
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustBackItemByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = v_wwk_42_mx_stocpklistaccoApp.GetItemByDocuNO(FDocuNO);
                result = data.ToJson();
            }
            else
            {

                string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = v_wwk_44_mx_stocpklistacco_midApp.GetItemByDocuNO(FDocuNO);
                    result = data.ToJson();
                }
                else
                {
                    var data = v_wwk_47_mx_stocpklistacco_arcApp.GetItemByDocuNO(FDocuNO);
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustBackOrder(string number)
        {
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P7");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList(OutEntrustBackType);
            ViewBag.fprocompanyList = zsj_b1_gh_supplierinformationApp.GetList("IsProduct = '1'");
            //ViewBag.fdocunoTemp = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "外委库返修", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitOutEntrustBackForm(string status, WWK_41_ML_StoCPKConAccoEntity entity, string detail, string keyValue)
        {
            string DocNum = "";
            string FFacNum = "";
            if (entity.FDocuTypeNO == "WX")
            {
                FFacNum = "外委库返修";
            }
            WWK_42_MX_StoCPKListAccoEntity detailEntity = null;
            if (entity != null)
            {
                entity.FAccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
                detailEntity = detail.ToObject<WWK_42_MX_StoCPKListAccoEntity>();
            }
            if (status == "I")
            {
                if (!string.IsNullOrEmpty(entity.FDocuNO))
                {
                    var list = wwk_42_mx_stocpklistaccoApp.GetList(entity.FDocuNO, detailEntity.FProCompanyNO, detailEntity.FProductionNO);
                    if (list.Count > 0)
                    {
                        return Error("当前单据中已存在相同的零件和制造单位，返修信息输入操作失败。");
                    }
                }
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataInsert(UseUnit, entity, detailEntity, OperatorProvider.Provider.GetCurrent().UserCode, FactoryFlag, FFacNum, "正式", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("返修信息输入操作成功。", entity);
                }
                else
                {
                    return Error("返修信息输入操作失败。");
                }
            }
            else if (status == "D")
            {
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataDelete(keyValue, OperatorProvider.Provider.GetCurrent().UserCode);
                if (result)
                {
                    return Success("返修信息删除操作成功。", entity);
                }
                else
                {
                    return Error("返修信息删除操作失败。");
                }
            }
            else if (status == "U")
            {
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataUpdate(detailEntity.FDocuListID, detailEntity.FQuantity, detailEntity.FPrice_KP, OperatorProvider.Provider.GetCurrent().UserCode);
                if (result)
                {
                    return Success("返修信息修改操作成功。", entity);
                }
                else
                {
                    return Error("返修信息修改操作失败。");
                }
            }
            else if (status == "P")
            {
                bool result = false;
                foreach (string item in keyValue.Split(','))
                {
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataCheck(UseUnit, item, OperatorProvider.Provider.GetCurrent().UserCode);
                }
                if (result)
                {
                    return Success("返修信息审核操作成功。", entity);
                }
                else
                {
                    return Error("返修信息审核操作失败。");
                }
            }
            else if (status == "C")
            {
                V_WWK_44_MX_StoCPKListAcco_MidEntity midEntity = v_wwk_44_mx_stocpklistacco_midApp.GetForm(keyValue);
                if (midEntity.FQuantity.HasValue && midEntity.FQuantity.Value > 0)
                {
                    bool result = false;
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataRevoke(keyValue, OperatorProvider.Provider.GetCurrent().UserCode, FactoryFlag, FFacNum, "正式", out DocNum);
                    if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                    {
                        entity.FDocuNO = DocNum;
                    }
                    if (result)
                    {
                        return Success("返修信息冲红操作成功。", entity);
                    }
                    else
                    {
                        return Error("当前库存不足，返修信息冲红操作失败。");
                    }
                }
                else
                {
                    return Error("当前单据为冲红单，不可再进行冲红操作。");
                }
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        #endregion

        #region 废品更换
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustWaste(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("IsProduct = '1'");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P7");
            ViewBag.accountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustWasteListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            var data = new
            {
                rows = v_wwk_42_mx_stocpklistaccoApp.GetList(pagination, OutEntrustWasteType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustWasteDocListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            if (AccountDate == FAccountDate)
            {
                var data = new
                {
                    rows = v_wwk_44_mx_stocpklistacco_midApp.GetList(pagination, OutEntrustWasteType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
            else
            {
                var data = new
                {
                    rows = v_wwk_47_mx_stocpklistacco_arcApp.GetList(pagination, OutEntrustWasteType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustWasteInput(string status, string number)
        {
            ViewBag.status = status != "B" ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList(OutEntrustWasteType);
            ViewBag.fdocunoTemp = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "外委库废品更换", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustWasteListByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = new
                {
                    rows = v_wwk_42_mx_stocpklistaccoApp.GetListByDocuNO(FDocuNO)
                };
                result = data.ToJson();
            }
            else
            {

                string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = new
                    {
                        rows = v_wwk_44_mx_stocpklistacco_midApp.GetListByDocuNO(FDocuNO)
                    };
                    result = data.ToJson();
                }
                else
                {
                    var data = new
                    {
                        rows = v_wwk_47_mx_stocpklistacco_arcApp.GetListByDocuNO(FDocuNO)
                    };
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustWasteItemByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = v_wwk_42_mx_stocpklistaccoApp.GetItemByDocuNO(FDocuNO);
                result = data.ToJson();
            }
            else
            {

                string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = v_wwk_44_mx_stocpklistacco_midApp.GetItemByDocuNO(FDocuNO);
                    result = data.ToJson();
                }
                else
                {
                    var data = v_wwk_47_mx_stocpklistacco_arcApp.GetItemByDocuNO(FDocuNO);
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustWasteOrder(string number)
        {
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P7");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList(OutEntrustWasteType);
            ViewBag.fprocompanyList = zsj_b1_gh_supplierinformationApp.GetList("IsProduct = '1'");
            //ViewBag.fdocunoTemp = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "外委库废品更换", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitOutEntrustWasteForm(string status, WWK_41_ML_StoCPKConAccoEntity entity, string detail, string keyValue)
        {
            string FFacNum = "";
            string DocNum = "";
            if (entity.FDocuTypeNO == "WS")
            {
                FFacNum = "外委库废品更换";
            }
            WWK_42_MX_StoCPKListAccoEntity detailEntity = null;
            if (entity != null)
            {
                entity.FAccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
                detailEntity = detail.ToObject<WWK_42_MX_StoCPKListAccoEntity>();
            }
            if (status == "I")
            {
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataInsert(UseUnit, entity, detailEntity, OperatorProvider.Provider.GetCurrent().UserCode, FactoryFlag, FFacNum, "正式", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("报损信息输入操作成功。", entity);
                }
                else
                {
                    return Error("报损信息输入操作失败。");
                }
            }
            else if (status == "D")
            {
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataDelete(keyValue, OperatorProvider.Provider.GetCurrent().UserCode);
                if (result)
                {
                    return Success("报损信息删除操作成功。", entity);
                }
                else
                {
                    return Error("报损信息删除操作失败。");
                }
            }
            else if (status == "U")
            {
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataUpdate(detailEntity.FDocuListID, detailEntity.FQuantity, detailEntity.FPrice_KP, OperatorProvider.Provider.GetCurrent().UserCode);
                if (result)
                {
                    return Success("报损信息修改操作成功。", entity);
                }
                else
                {
                    return Error("报损信息修改操作失败。");
                }
            }
            else if (status == "P")
            {
                bool result = false;
                foreach (string item in keyValue.Split(','))
                {
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataCheck(UseUnit, item, OperatorProvider.Provider.GetCurrent().UserCode);
                }
                if (result)
                {
                    return Success("报损信息审核操作成功。", entity);
                }
                else
                {
                    return Error("报损信息审核操作失败。");
                }
            }
            else if (status == "C")
            {
                V_WWK_44_MX_StoCPKListAcco_MidEntity midEntity = v_wwk_44_mx_stocpklistacco_midApp.GetForm(keyValue);
                if (midEntity.FQuantity.HasValue && midEntity.FQuantity.Value > 0)
                {
                    bool result = false;
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataRevoke(keyValue, OperatorProvider.Provider.GetCurrent().UserCode, FactoryFlag, FFacNum, "正式", out DocNum);
                    if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                    {
                        entity.FDocuNO = DocNum;
                    }
                    if (result)
                    {
                        return Success("报损信息冲红操作成功。", entity);
                    }
                    else
                    {
                        return Error("当前库存不足，报损信息冲红操作失败。");
                    }
                }
                else
                {
                    return Error("当前单据为冲红单，不可再进行冲红操作。");
                }
            }
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        #endregion

        #region 盘点
        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustShelves(string status)
        {
            status = string.IsNullOrEmpty(status) ? "0" : status;
            ViewBag.status = status;
            ViewBag.fhappencomList = zsj_b1_gh_supplierinformationApp.GetList("IsProduct = '1'");
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P7");
            ViewBag.accountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustShelvesListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            var data = new
            {
                rows = v_wwk_42_mx_stocpklistaccoApp.GetList(pagination, OutEntrustShelvesType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustShelvesDocListJson(Pagination pagination, string FDocuNO, string FHappenComNO, string FProductionNO, string FStoreNO, string FCurDate, string FCredence, string FAccountDate)
        {
            string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            if (AccountDate == FAccountDate)
            {
                var data = new
                {
                    rows = v_wwk_44_mx_stocpklistacco_midApp.GetList(pagination, OutEntrustShelvesType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
            else
            {
                var data = new
                {
                    rows = v_wwk_47_mx_stocpklistacco_arcApp.GetList(pagination, OutEntrustShelvesType, FAccountDate, FDocuNO, FHappenComNO, FProductionNO, FStoreNO, FCurDate, FCredence),
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustShelvesInput(string status, string number)
        {
            ViewBag.status = status != "B" ? "I" : status;
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList(OutEntrustShelvesType);
            ViewBag.fdocunoTemp = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "外委库盘点", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustShelvesListByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = new
                {
                    rows = v_wwk_42_mx_stocpklistaccoApp.GetListByDocuNO(FDocuNO)
                };
                result = data.ToJson();
            }
            else
            {

                string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = new
                    {
                        rows = v_wwk_44_mx_stocpklistacco_midApp.GetListByDocuNO(FDocuNO)
                    };
                    result = data.ToJson();
                }
                else
                {
                    var data = new
                    {
                        rows = v_wwk_47_mx_stocpklistacco_arcApp.GetListByDocuNO(FDocuNO)
                    };
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetOutEntrustShelvesItemByDocuNOJson(string FDocuNO, string FAccountDate)
        {
            string result = "";
            if (string.IsNullOrEmpty(FAccountDate))
            {
                var data = v_wwk_42_mx_stocpklistaccoApp.GetItemByDocuNO(FDocuNO);
                result = data.ToJson();
            }
            else
            {

                string AccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
                if (AccountDate == FAccountDate)
                {
                    var data = v_wwk_44_mx_stocpklistacco_midApp.GetItemByDocuNO(FDocuNO);
                    result = data.ToJson();
                }
                else
                {
                    var data = v_wwk_47_mx_stocpklistacco_arcApp.GetItemByDocuNO(FDocuNO);
                    result = data.ToJson();
                }
            }
            return Content(result);
        }

        [HttpGet]
        [HandlerAuthorize]
        public ActionResult OutEntrustShelvesOrder(string number)
        {
            ViewBag.number = (number == null) ? "" : number;
            ViewBag.fstoreList = cpk_zd_11_datstorehouseApp.GetSelectList().FindAll(t => t.FStoreType == "P7");
            ViewBag.fdocutypenoList = bus_sj_dictionaryApp.GetItemList(OutEntrustShelvesType);
            ViewBag.fprocompanyList = zsj_b1_gh_supplierinformationApp.GetList("IsProduct = '1'");
            //ViewBag.fdocunoTemp = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "外委盘点", OperatorProvider.Provider.GetCurrent().UserCode, "", "临时");
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitOutEntrustShelvesForm(string status, WWK_41_ML_StoCPKConAccoEntity entity, string detail, string keyValue)
        {
            string FFacNum = "";
            string DocNum = "";
            if (entity.FDocuTypeNO == "WP")
            {
                FFacNum = "外委库盘点";
            }
            WWK_42_MX_StoCPKListAccoEntity detailEntity = null;
            if (entity != null)
            {
                entity.FAccountDate = GetDocumentNum.GetNum(UseUnit, FactoryFlag, "台账日期外委", OperatorProvider.Provider.GetCurrent().UserCode, "", "正式");
                detailEntity = detail.ToObject<WWK_42_MX_StoCPKListAccoEntity>();
            }
            if (status == "I")
            {
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataInsert(UseUnit, entity, detailEntity, OperatorProvider.Provider.GetCurrent().UserCode, FactoryFlag, FFacNum, "正式", out DocNum);
                if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
                {
                    entity.FDocuNO = DocNum;
                }
                if (result)
                {
                    return Success("盘点信息输入操作成功。", entity);
                }
                else
                {
                    return Error("盘点信息输入操作失败。");
                }
            }
            else if (status == "D")
            {
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataDelete(keyValue, OperatorProvider.Provider.GetCurrent().UserCode);
                if (result)
                {
                    return Success("盘点信息删除操作成功。", entity);
                }
                else
                {
                    return Error("盘点信息删除操作失败。");
                }
            }
            else if (status == "U")
            {
                bool result = false;
                result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataUpdate(detailEntity.FDocuListID, detailEntity.FQuantity, detailEntity.FPrice_KP, OperatorProvider.Provider.GetCurrent().UserCode);
                if (result)
                {
                    return Success("盘点信息修改操作成功。", entity);
                }
                else
                {
                    return Error("盘点信息修改操作失败。");
                }
            }
            else if (status == "P")
            {
                bool result = false;
                foreach (string item in keyValue.Split(','))
                {
                    result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataCheck(UseUnit, item, OperatorProvider.Provider.GetCurrent().UserCode);
                }
                if (result)
                {
                    return Success("盘点信息审核操作成功。", entity);
                }
                else
                {
                    return Error("盘点信息审核操作失败。");
                }
            }
            //else if (status == "C")
            //{
            //    V_WWK_44_MX_StoCPKListAcco_MidEntity midEntity = v_wwk_44_mx_stocpklistacco_midApp.GetForm(keyValue);
            //    if (midEntity.FQuantity.HasValue && midEntity.FQuantity.Value > 0)
            //    {
            //        bool result = false;
            //        result = FriendStar.Repository.Infrastructure.ExecProcedure.InOutStoWwkStockCataRevoke(keyValue, OperatorProvider.Provider.GetCurrent().UserCode, FactoryFlag, FFacNum, "正式", out DocNum);
            //        if (!string.IsNullOrEmpty(DocNum) && string.IsNullOrEmpty(entity.FDocuNO))
            //        {
            //            entity.FDocuNO = DocNum;
            //        }
            //        if (result)
            //        {
            //            return Success("盘点信息冲红操作成功。", entity);
            //        }
            //        else
            //        {
            //            return Error("当前库存不足，盘点信息冲红操作失败。");
            //        }
            //    }
            //    else
            //    {
            //        return Error("当前单据为冲红单，不可再进行冲红操作。");
            //    }
            //}
            else
            {
                return Error("不可识别的操作类型。");
            }
        }

        #endregion

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFProductionWWEnterListJson(Pagination pagination, string productionNO, string productionName)
        {
            var data = new
            {
                rows = v_zsj_12_gh_suproduction_datstorwwApp.GetList(pagination, productionNO, productionName),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFProductionWWOutListJson(Pagination pagination, string productionNO, string productionName, bool? isShowZero)
        {
            var data = new
            {
                rows = v_cpk_61_pc_stocpkaiaoacco_aywwApp.GetList(pagination, productionNO, productionName, null),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }


        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetHappenCompanyListJson(string type)
        {
            if (type == "WI" || type == "WO")
            {
                var data = zsj_b1_gh_supplierinformationApp.GetList("(IsProduct = '1') AND (IsInsideUnit = '1')").OrderBy(p => p.UnitNO);
                return Content(data.ToJson());
            }
            else if (type == "WR" || type == "WC")
            {
                var data = zsj_b1_gh_supplierinformationApp.GetList("(IsProduct = '1') AND (IsInsideUnit = '0'  OR IsInsideUnit IS NULL)").OrderBy(p => p.UnitNO);
                return Content(data.ToJson());
            }
            else if (type == "WX" || type == "WP")
            {
                var data = zsj_b1_gh_supplierinformationApp.GetList("(IsInsideUnit = '0')").OrderBy(p => p.UnitNO);
                return Content(data.ToJson());
            }
            else if (type == "WS")
            {
                var data = zsj_b1_gh_supplierinformationApp.GetList("(IsProduct = '1') AND (IsInsideUnit = '0')").OrderBy(p => p.UnitNO);
                return Content(data.ToJson());
            }
            else
            {
                return Content("");
            }
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetStoreHouseSetListJson(string storeNO)
        {
            var data = wwk_zd_12_datstorehousesetApp.GetList(storeNO);
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult GetPrintDetailsData(bool isDefaultDate, bool isArchive, string ids)
        {
            var data = app.GetPrintDetailsData(isDefaultDate, isArchive, ids);
            return Success("获取打印数据成功。", data);
        }

        public ActionResult OutEntrustShelves()   //外委冲压件盘点盈亏登记
        {
            return View();
        }
        public ActionResult OutEntrustLegter()    //外委冲压件仓库明细台帐
        {
            return View();
        }
        public ActionResult OutEntrustReport()
        {
            return View();
        }
        
    }
}

 